package com.mql.ganio.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.mql.ganio.ui.base.BaseFragment;

import java.util.List;


/**
 * @创建者 mql
 * @描述 通用的ViewPager适配器(FragmentPagerAdapter)
 */
public class CommonFragmentPagerAdapter extends FragmentPagerAdapter {


    private List<String> mTitleList;
    private List<BaseFragment> mFragments;

    public CommonFragmentPagerAdapter(FragmentManager fm, List<BaseFragment> fragments) {
        super(fm);
        mFragments = fragments;
    }

    //根据传入的viewPagerType，在getTitle中返回不同的标题信息
    public CommonFragmentPagerAdapter(FragmentManager fm, List<BaseFragment> fragments, List<String> mTitleList) {
        this(fm, fragments);
        this.mFragments = fragments;
        this.mTitleList = mTitleList;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments != null ? mFragments.size() : 0;
    }

    /**
     * 首页显示title，每日推荐等..
     * 若有问题，移到对应单独页面
     */
    @Override
    public CharSequence getPageTitle(int position) {
        if (mTitleList != null) {
            return mTitleList.get(position);
        } else {
            return "";
        }
    }

}
